package com.sjqi.demo.config;

import com.sjqi.demo.executor.CachingExecutor;
import com.sjqi.demo.executor.Executor;
import com.sjqi.demo.handler.StatementHandler;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author qishaojun
 */
public class Configuration {
    private DataSource dataSource;
    private Map<String, MappedStatement> mappedStatements = new HashMap<>();
    private boolean useCache = true;

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public MappedStatement getMappedStatement(String statementId) {
        return mappedStatements.get(statementId);
    }

    public void addMappedStatement(String statementId, MappedStatement statement) {
        this.mappedStatements.put(statementId, statement);
    }

    public Executor newExecutor(String executorType) {
        executorType = null == executorType || "".equals(executorType) ? "simple" : executorType;
        Executor executor = null;
        if (executorType.equals("simple")) {
            //
        }
        //...
        //二级缓存对执行器进行包装
        if (useCache) {
            executor = new CachingExecutor(executor);
        }
        return null;
    }

    public StatementHandler newStatementHandler(String statementType) {
        //路由的 RoutingStatementHandler
        //RoutingStatementHandler 里面做的if else 的判断

        if (statementType == null || "".equals(statementType)) {

        }
        return null;
    }
}
